<template>
  <div class="dashboard">
    <div class="welcome-section">
      <h1>欢迎回来，{{ userStore.user?.name || '同学' }}！</h1>
      <p class="welcome-text">今天是 {{ currentDate }}，祝您学习愉快！</p>
    </div>
<!---->
    <div class="stats-section">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-card class="stat-card" shadow="never">
            <div class="stat-content">
              <div class="stat-icon">
                <el-icon><Document /></el-icon>
              </div>
              <div class="stat-info">
                <div class="stat-number">{{ stats.applications }}</div>
                <div class="stat-label">我的申请</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="stat-card" shadow="never">
            <div class="stat-content">
              <div class="stat-icon">
                <el-icon><Clock /></el-icon>
              </div>
              <div class="stat-info">
                <div class="stat-number">{{ stats.workHours }}</div>
                <div class="stat-label">本月工时</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="stat-card" shadow="never">
            <div class="stat-content">
              <div class="stat-icon">
                <el-icon><Money /></el-icon>
              </div>
              <div class="stat-info">
                <div class="stat-number">¥{{ stats.salary }}</div>
                <div class="stat-label">本月工资</div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <div class="recent-section">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-card class="recent-card" shadow="never">
            <template #header>
              <div class="card-header">
                <span>最近申请</span>
                <el-button type="text" size="small" @click="$router.push('/student/my-application')">
                  查看全部
                </el-button>
              </div>
            </template>
            <div class="recent-list">
              <div v-for="application in recentApplications" :key="application.id" class="recent-item">
                <div class="item-content">
                  <div class="item-title">{{ application.positionName }}</div>
                  <div class="item-status">
                    <el-tag :type="getStatusType(application.status)" size="small">
                      {{ getStatusText(application.status) }}
                    </el-tag>
                  </div>
                </div>
                <div class="item-time">{{ application.applyTime }}</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="12">
          <el-card class="recent-card" shadow="never">
            <template #header>
              <div class="card-header">
                <span>工时记录</span>
                <el-button type="text" size="small" @click="$router.push('/student/work-time-records')">
                  查看全部
                </el-button>
              </div>
            </template>
            <div class="recent-list">
              <div v-for="record in recentRecords" :key="record.id" class="recent-item">
                <div class="item-content">
                  <div class="item-title">{{ record.positionName }}</div>
                  <div class="item-hours">{{ record.hours }}小时</div>
                </div>
                <div class="item-time">{{ record.workDate }}</div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useUserStore } from '@/stores/user'
import { Document, Clock, Money } from '@element-plus/icons-vue'

const userStore = useUserStore()

// 当前日期
const currentDate = computed(() => {
  const now = new Date()
  return now.toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    weekday: 'long'
  })
})


// 获取状态类型
function getStatusType(status) {
  const statusMap = {
    pending: 'warning',
    approved: 'success',
    rejected: 'danger'
  }
  return statusMap[status] || 'info'
}

// 获取状态文本
function getStatusText(status) {
  const statusMap = {
    pending: '待审核',
    approved: '已通过',
    rejected: '已拒绝'
  }
  return statusMap[status] || '未知'
}
</script>

<style scoped>
.dashboard {
  padding: 0;
}

.welcome-section {
  margin-bottom: 32px;
  text-align: center;
}

.welcome-section h1 {
  font-size: 28px;
  font-weight: 600;
  color: #303133;
  margin: 0 0 8px 0;
}

.welcome-text {
  font-size: 16px;
  color: #909399;
  margin: 0;
}

.stats-section {
  margin-bottom: 32px;
}

.stat-card {
  border: none;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.04);
}

.stat-content {
  display: flex;
  align-items: center;
  padding: 20px;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-info {
  flex: 1;
}

.stat-number {
  font-size: 28px;
  font-weight: 700;
  color: #303133;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 14px;
  color: #909399;
  font-weight: 500;
}

.recent-section {
  margin-bottom: 32px;
}

.recent-card {
  border: none;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.04);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: #303133;
}

.recent-list {
  padding: 16px 0;
}

.recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;
}

.recent-item:last-child {
  border-bottom: none;
}

.item-content {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.item-title {
  font-size: 14px;
  color: #303133;
  font-weight: 500;
}

.item-status {
  margin-left: 16px;
}

.item-hours {
  font-size: 14px;
  color: #409EFF;
  font-weight: 500;
  margin-left: 16px;
}

.item-time {
  font-size: 12px;
  color: #909399;
  margin-left: 16px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .stats-section .el-col,
  .recent-section .el-col {
    margin-bottom: 16px;
  }
  
  .welcome-section h1 {
    font-size: 24px;
  }
  
  .stat-number {
    font-size: 24px;
  }
}
</style> 